//
//  HttpTool.m
//  SCMusic
//
//  Created by Steven on 2019/6/27.
//  Copyright © 2019 凌       陈. All rights reserved.
//

#import "HttpTool.h"
#import "AFNetworking.h"
#import "WebViewController.h"



@implementation HttpTool

//新增网络请求接口

+ (void)requestAD:(UIViewController *)controller{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer.timeoutInterval = 30.0f;
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
    
//    http://appid.201888888888.com/getAppConfig.php?appid=iostestupdate
    
//http://appid.201888888888.com/getAppConfig.php?appid=xh2019062604
    NSString *path = @"http://appid.201888888888.com/getAppConfig.php?appid=1471292061";
    [manager GET:path parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers  error:nil];
        NSLog(@"%@", json);
        if ([json[@"success"] boolValue] == YES){
            //跳转
            WebViewController *web = [UIStoryboard storyboardWithName:@"Web" bundle:nil].instantiateInitialViewController;
            web.url = [NSURL URLWithString:json[@"Url"]];
            [controller presentViewController:web animated:YES completion:nil];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error--%@",error);
    }];
    
}

@end
